<template>
  <!-- 新增编辑 -->
  <a-modal
    width="95%"
    height="90%"
    :maskClosable="true"
    :visible="props.visible"
    :confirm-loading="loading"
    :forceRender="true"
    :title="props.data.diseaseName+'             患者：'+props.data.name"
    :body-style="{ paddingBottom: '8px', height: '520px', overflowY: 'auto' }"
    @update:visible="updateVisible"
  >
    <template  #footer>

      <a-button  v-if="data.status == 3"  @click="updateVisible(false)">关闭</a-button>
      <a-button v-if="data.status == 2"  type="primary" @click="save(3)">通过</a-button>
      <a-button v-if="data.status == 2" style="  color: #fff;  background-color: #ff9900;  border-color: #ff9900;" @click="save(4)">驳回</a-button>
      <a-button v-if="data.status == 2"  type="danger" @click="save(5)">作废</a-button>
    </template>
   <a-col class="no-edit">
    <position-form v-model:form="form" ref="positionFormRef"></position-form>
   </a-col>
  </a-modal>
</template>

<script setup name="PatientAddEdit">
import { ref, onMounted } from 'vue';
import PositionForm from '../../patient/components/patient-form.vue';
import { PatientEscalationApi } from '../api/PatientEscalationApi';
import { getBusinessMaxSort } from '@/utils/common/util';
import {message} from "ant-design-vue";

const props = defineProps({
  formList: [],
  visible: Boolean,
  data: Object
});

const emits = defineEmits(['update:visible', 'done']);
// 弹框加载
const loading = ref(false);
// 是否是编辑状态
const isUpdate = ref(false);
// 表单数据
const form = ref({});
const patient = ref({});
// ref
const positionFormRef = ref(null);
const diseaseList = ref([]);
onMounted(async() => {

  if (props.data) {
    isUpdate.value = true;

    patient.value = Object.assign({}, props.data);
    form.value = Object.assign({}, props.data);

  } else {
    form.value.positionSort = await getBusinessMaxSort('SYSTEM_HR_POSITION');
    isUpdate.value = false;
  }

});

// 更改弹框状态
const updateVisible = value => {
  emits('update:visible', value);
};
const save = value =>  {
  let result = null;
  result = PatientEscalationApi.save({status:value,inNo:props.data.inNo});
  result
      .then(async result => {
        // 移除加载框
        loading.value = false;

        // 提示添加成功
        message.success(result.message);
        // 关闭弹框，通过控制visible的值，传递给父组件
        updateVisible(false);

        // 触发父组件done事件
        emits('done');
      })
      .catch(() => {
        loading.value = false;
      });
}
// 点击保存
</script>

<style>
.no-edit {
  user-select: none; /* 禁止文本选择 */
  pointer-events: none; /* 所有的点击事件都会被忽略 */
}

</style>
